package volatiledemo;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * @description:
 * @author: jhy
 * @time: 2021/4/12 15:46
 */

//使用原子类  -->弥补volatile关键字不能保证原子类的缺点
public class VolatileDemo3 {

    public static void main(String[] args) {
        new MyThread2().start();
        new MyThread2().start();
        new MyThread2().start();
        new MyThread2().start();
        new MyThread2().start();
    }
}

class MyThread2 extends Thread{

    public volatile static AtomicInteger count = new AtomicInteger(0);

    @Override
    public void run() {
        for(int i = 0;i < 10000;i++){
            System.out.println(count.incrementAndGet());
        }

    }
}

